<template>
  <div id="app">
    <cube-view />
  </div>
</template>
<script>
import CubeView from "./components/cube-view.vue";
import { MessageKey, EventManager } from "./api/message";

export default {
  name: "app",
  components: {
    CubeView
  },
  created() {
    this.registerEvent();
  },
  methods: {
    registerEvent() {
      EventManager.Register(
        MessageKey.errorCode,
        this.errorCode.bind(this),
        this
      );
      EventManager.Register(MessageKey.error, this.errorTip.bind(this), this);
      this.$once("hook:beforeDestroy", () => {
        EventManager.UnRegister(MessageKey.errorCode, this);
        EventManager.UnRegister(MessageKey.error, this);
      });
    },
    errorTip(error) {
      this.$toast(error);
    },
    errorCode(errorCode) {
      this.$toastErrorCode(errorCode);
      if (errorCode == 10004 || errorCode == 10415) {
        this.$router.push({ path: "/login" });
      }
    }
  }
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
